<template>
  <div class="wrap">
    <div class="list">
      <div class="ul">
        <div class="li" @click="goHref('nickName')">
          <div class="left">
            <div class="iconfont icon-jiankangzheng"></div>
            <div class="txt">昵称<strong></strong></div>
          </div>
          <div class="right">
            <div class="txt">{{ info.nick_name }}</div>
            <img src="./../../assets/img/right.png" />
          </div>
        </div>
        <div class="li" @click="goHref('age')">
          <div class="left">
            <div class="iconfont icon-jiankangzheng"></div>
            <div class="txt">年龄<strong></strong></div>
          </div>
          <div class="right">
            <div class="txt">{{ info.age }}</div>
            <img src="./../../assets/img/right.png" />
          </div>
        </div>
        <div class="li" @click="goHref('sex')">
          <div class="left">
            <div class="iconfont icon-jiankangzheng"></div>
            <div class="txt">性别<strong></strong></div>
          </div>
          <div class="right">
            <div class="txt">{{ info.gender == 1 ? '男' : '女' }}</div>
            <img src="./../../assets/img/right.png" />
          </div>
        </div>
        <div class="li" @click="goHref('facephoto')">
          <div class="left">
            <div class="iconfont icon-yongpiao"></div>
            <div class="txt">人脸照片<strong></strong></div>
          </div>
          <div class="right">
            <img
              class="right-pic"
              :src="info.face_photo == '' ? defaultPic : info.face_photo"
            />
            <img class="right-icon" src="./../../assets/img/arrow-right.png" />
          </div>
        </div>
        <div class="li" @click="goHref('healthCard')">
          <div class="left">
            <div class="iconfont icon-jiankangzheng"></div>
            <div class="txt">健康证<strong></strong></div>
          </div>
          <div class="right">
            <img
              class="right-pic"
              :src="
                info?.health?.image_url == ''
                  ? defaultPic
                  : info?.health?.image_url
              "
            />
            <img class="right-icon" src="./../../assets/img/arrow-right.png" />
          </div>
        </div>
        <div class="li" @click="goHref('titck')">
          <div class="left">
            <div class="iconfont icon-jiankangzheng"></div>
            <div class="txt">我的泳票<strong></strong></div>
          </div>
          <div class="right">
            <div class="txt">{{ titckNum }} 张</div>
            <img src="./../../assets/img/right.png" />
          </div>
        </div>
        <div class="li" @click="goHref('group')">
          <div class="left">
            <div class="iconfont icon-jiankangzheng"></div>
            <div class="txt">我的群组<strong></strong></div>
          </div>
          <div class="right">
            <div class="txt">{{ groupNum }}个</div>
            <img src="./../../assets/img/right.png" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref, watch } from 'vue'
// import wx from 'weixin-js-sdk'
import { postData } from '@/request/request.js'
import { useRoute } from 'vue-router/dist/vue-router'
import defaultPic from '@/assets/img/default-pic.png'
let route = useRoute()
let query = route.query
localStorage.clear()
localStorage.setItem('user_id', query.user_id || '')
localStorage.setItem('access_token', query.access_token || '')
localStorage.setItem('open_id', query.open_id || '')
localStorage.setItem('currentPath', query.currentPath || '')
localStorage.setItem('carriedUserid', query.carriedUserid || '')

const carriedUserid = ref('')
let info = ref({})
let titckNum = ref(0)
let groupNum = ref(0)

let initInfo = () => {
  postData('/user/carried/info', {
    carried_user_id: carriedUserid.value,
    with_health: 1,
  })
    .then((res) => {
      info.value = res.datas
    })
    .catch(() => {})
}

//泳票数量
const initTitckList = () => {
  postData('/user/ticket/list', { user_id: carriedUserid.value })
    .then((res) => {
      titckNum.value = res.datas.tickets.length
    })
    .catch((err) => {
      console.log(err)
    })
}

//我的群组
const initGroups = () => {
  postData('/user/group/applying/list', { user_id: carriedUserid.value })
    .then((res) => {
      if (res.code == 0) {
        groupNum.value = res.datas.applyings.length
      } else {
        showToast(res.msg)
      }
    })
    .catch((err) => {
      console.log(err)
    })
}

const goHref = (txt) => {
  if (txt == 'nickName') {
    wx &&
      wx.miniProgram.navigateTo({
        url: `/pagesC/carryUserDetail/carryUserNickName?carriedUserid=${carriedUserid.value}`,
      })
  } else if (txt == 'age') {
    wx &&
      wx.miniProgram.navigateTo({
        url: `/pagesC/carryUserDetail/carryUserAge?carriedUserid=${carriedUserid.value}`,
      })
  } else if (txt == 'sex') {
    wx &&
      wx.miniProgram.navigateTo({
        url: `/pagesC/carryUserDetail/carryUserSex?carriedUserid=${carriedUserid.value}`,
      })
  } else if (txt == 'healthCard') {
    wx &&
      wx.miniProgram.navigateTo({
        url: `/pagesC/carryUserDetail/carryUserHealthCard?carriedUserid=${carriedUserid.value}`,
      })
  } else if (txt == 'facephoto') {
    wx &&
      wx.miniProgram.navigateTo({
        url: `/pagesC/carryUserDetail/carryUserFacephoto?carriedUserid=${carriedUserid.value}`,
      })
  } else if (txt == 'group') {
    wx &&
      wx.miniProgram.navigateTo({
        url: `/pagesC/myGroup/index?carriedUserid=${carriedUserid.value}`,
      })
  } else if (txt == 'titck') {
    wx &&
      wx.miniProgram.navigateTo({
        url: `/pagesC/carryUserDetail/carryUserTitck?carriedUserid=${carriedUserid.value}`,
      })
  }
}

onMounted(() => {
  carriedUserid.value = route.query.carriedUserid
  initInfo()
  initTitckList()
  initGroups()
})

watch(
  () => route.fullPath,
  () => {
    carriedUserid.value = route.query.carriedUserid
    initInfo()
    initTitckList()
    initGroups()
  }
)
</script>

<style scoped>
.wrap {
  width: 100%;
  position: relative;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  background: #f8f8f8;
  color: #333;
  font-size: 0.16rem;
}
.list {
  width: 96%;
  border-radius: 0.08rem;
  background: #fff;
  height: auto;
  margin: 0 auto;
}
.list .ul {
  margin: 0;
  padding: 0;
  margin-top: 0.05rem;
  display: flex;
  flex-flow: column;
  justify-content: flex-start;
}
.list .ul .li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 0.5rem;
  line-height: 0.5rem;
  border-bottom: 1px solid #f5f5f0;
}
.list .ul .li .left {
}
.list .ul .li .left .txt {
  margin-left: 0.075rem;
}
.li img {
  width: 0.2rem;
  height: 0.2rem;
  margin-left: 0.1rem;
}

.list .ul .li .right {
  height: 100%;
  flex: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  /* font-size: 0.14rem; */
}

.right-txt {
}
.right-pic {
  width: 0.26rem;
  height: 0.26rem;
}
.right-icon {
  margin-left: 0.1rem;
  width: 0.16rem;
  height: 0.16rem;
}
</style>
